<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.sql.*"%>
<%@ page import="java.util.*"  %>
<%@ page import="java.net.*"  %>
<%@ page import="it.univpm.diiga.semanticsearch.ricerca.*"  %>
<%@ page import="it.univpm.diiga.semanticsearch.indicizzazione.*"  %>
<%@ page import="it.univpm.diiga.semanticsearch.servizi.*"  %>
<%@ page import="it.univpm.diiga.semanticsearch.configurazione.*"  %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>UpadateRank</title>

	<%

		String servName=request.getParameter("servName");
		String servLink=request.getParameter("servLink");
		boolean wsdl=request.getParameter("wsdl") == null || request.getParameter("wsdl").equals("null") ? false : true;
		boolean bpel=request.getParameter("bpel") == null || request.getParameter("bpel").equals("null") ? false : true;		
		boolean swsal=request.getParameter("swsal") == null || request.getParameter("swsal").equals("null") ? false : true;
		String wsdlL="";
		String bpelL="";
		String swsalL="";
		String error="";
		int rank=0;
		
		
		if (wsdl)
			wsdlL=request.getParameter("wsdl");
		if (bpel)
			bpelL=request.getParameter("bpel");
		if (swsal)
			swsalL=request.getParameter("swsal");
			
		if ( wsdl || bpel || swsal ){
			Criterio_ranking ranker=new Criterio_ranking("webapps/webids/rank.xml");
			ArrayList<Link> listLink=new ArrayList<Link>();
			
			Link link=new Link(servName,servLink,wsdlL,bpelL,swsalL,null);
			try{
				Configuration.findRankConfiguration();
				rank=Configuration.getSave();
			}catch(Exception e){
				out.println(e);
			}
			listLink.add(link);
			ranker.updateRank(listLink,rank);
		}else{
			error="Attention, the link of the file selected are not valid!";
		}
	%>


<script type="text/javascript">
	function doRedirect(wsdl,bpel,swsal){
		if (wsdl){
			location.href=" <%=wsdlL%> ";
		}
		else if (bpel){
			location.href=" <%= bpelL %> ";
			
		}
		else if (swsal){
			location.href=" <%= swsalL %> ";
		}else{
			
		}
	}
	//window.setTimeout("doRedirect()", 4000);
</script>



</head>
<body onLoad="doRedirect('<%= wsdl %>','<%= bpel %>','<%= swsal %>')">
<%


	if (error=="")
		error=error;
	else{
		out.println("<script type='text/javascript'> alert(' "+ error + " ');self.close(); </script>");
	}
		


%>
</body>
</html>